package com.data.core.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.pojo.Result;
import com.common.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.data.core.entry.Notice;
import com.data.core.service.NoticeService;
import javax.annotation.Resource;

@Api(value = "公告相关API")
@RestController
@RequestMapping("notice")
public class NoticeController {

    @Resource
    private NoticeService noticeService;

    @ApiOperation(value = "保存公告",notes = "保存")
    @PostMapping(value = "save")
    public Result<?> save(@RequestBody NoticeVo noticeVo) throws Exception {
        Result result = new Result();
        result.OK(noticeService.save(noticeVo));
        return result;
    }

    @ApiOperation(value = "更新公告",notes = "更新")
    @PostMapping(value = "update")
    public Result<?> update(@RequestBody NoticeVo noticeVo) throws Exception {
        Result result = new Result();
        result.OK(noticeService.update(noticeVo));
        return result;
    }

    @ApiOperation(value = "查询问题信息",notes = "查询")
    @ApiImplicitParam(name = "id", value = "问题id", required = true, dataType = "Long")
    @PostMapping("find")
    public Result<?> findNoticeById(@RequestParam Long id) throws Exception {
        Result result = new Result();
        result.OK(noticeService.findNoticeById(id));
        return result;
    }

    @ApiOperation(value = "删除公告",notes = "删除")
    @ApiImplicitParam(name = "id", value = "公告id", required = true, dataType = "Long")
    @GetMapping("delete")
    public Result<?> delete(@RequestParam Long id) throws Exception {
        Result result = new Result();
        result.OK(noticeService.delete(id));
        return result;
    }

    @ApiOperation(value = "公告列表",notes = "列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", paramType = "query",required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "条数",paramType = "query",required = true,dataType = "int"),
    })
    @PostMapping("page")
    public Result<?> DictDataPage(@RequestBody NoticeVo noticeVo,
                                  @RequestParam(value = "pageNum") int pageNum,
                                  @RequestParam(value = "pageSize")  int pageSize) throws Exception {
        Result result = new Result();
        Page<Notice> page = new Page<>(pageNum,pageSize);
        result.OK(noticeService.noticePage(page,noticeVo));
        return result;
    }

}
